//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_playerRespawn.sqf"
#include <btc_macros.h>
TRACE_1("Start",_this);

BTC_respawn_cond = true;
if (BTC_active_lifes == 1) then {BTC_lifes = BTC_lifes - 1;};
if (BTC_active_lifes == 1 && BTC_lifes == 0) exitWith BTCR_fnc_outOfLifes;
if (BTC_active_lifes != 1 || BTC_lifes != 0) then
{
	deTach player;
	player setVariable ["BTC_need_revive",0,true];
	closeDialog 0;
	if (BTC_black_screen == 0) then {titleText ["", "BLACK OUT"];};
	sleep 0.2;
	titleText ["", "BLACK FADED"];
	if (vehicle player != player) then {unAssignVehicle player;player action ["eject", vehicle player];};
	player setPos getMarkerPos BTC_respawn_marker;
	sleep 1;
	closeDialog 0;
	player setDamage 0;
	player switchMove "amovpercmstpslowwrfldnon";
	player switchMove "";
	if (BTC_respawn_time > 0) then
	{
		player enableSimulation false;
		player attachTo [BTC_r_base_spawn,[0,0,6000]];
		//player setVelocity [0,0,0];
		sleep 1;
		private ["_n"];
		for [{_n = BTC_respawn_time}, {_n != 0}, {_n = _n - 1}] do
		{
			private ["_msg"];
			//player enableSimulation false;
			//player setpos [0,0,6000];
			//player setVelocity [0,0,0];
			titleText [format ["Respawn in %1",_n], "BLACK FADED"];
			sleep 1;
		};
	};
	player setVariable ["BTC_need_revive",0,true];
	closeDialog 0;
	sleep 0.1;
	BTC_respawn_cond = false;
	if (BTC_dlg_on_respawn != 0) then 
	{
		_dlg = [0] spawn BTCR_fnc_createDialogMobile;
	}
	else
	{
		BTC_r_base_spawn setPos getMarkerPos BTC_respawn_marker;
		player attachTo [BTC_r_base_spawn,[0,0,0]];
		sleep 0.1;
		deTach player;
		player setVelocity [0,0,0];
		player setPos getMarkerPos BTC_respawn_marker;
		player enableSimulation true;
		player switchMove "amovpercmstpsraswrfldnon";
		player switchMove "";//amovpercmstpsraswrfldnon		
		if (BTC_black_screen == 1 && BTC_respawn_time == 0) then {titleText ["", "BLACK IN"];sleep 2;titleText ["", "PLAIN"];};
		if (BTC_black_screen == 0 || BTC_respawn_time > 0) then 
		{	
			titleText ["", "BLACK IN"];
			sleep 2;
			titleText ["", "PLAIN"];
		};
	};
};
